Skip to content

Embed the coding-agent tracing daemon - #287

Open
Stephen Belanger (Qard) wants to merge 19 commits into
mainfrom
agent/bt-daemon-integration
Open

Embed the coding-agent tracing daemon#287
Stephen Belanger (Qard) wants to merge 19 commits into
mainfrom
agent/bt-daemon-integration

Conversation

@Qard

@Qard Stephen Belanger (Qard) commented Jul 29, 2026

Copy link
Copy Markdown

Dependencies

Depends on merged braintrustdata/braintrust-coding-agent-plugins#1, pinned at its squash-merge commit bebff4e0349fd9d2ee4a8ce1eeeafafee91ac74b.

That daemon PR in turn depends on braintrustdata/braintrust-sdk-rust#86, pinned at commit d33e806bf6ab9548d37355f6a5098a971ef150aa.

The plugin source cutover is intentionally deferred to stacked braintrustdata/braintrust-coding-agent-plugins#3, which must land only after this daemon is available in a released bt CLI.

Summary

This embeds the shared coding-agent tracing daemon in bt under the bt trace command family. bt trace setup and bt trace import are the user-facing commands. The daemon, hook, status, and stop subcommands remain directly callable by plugins and operators who know their names, but are hidden from public help and usage output as implementation details.

bt trace import codex <session-id> and bt trace import claude <session-id> locate and snapshot native session transcripts in the agents' standard data directories, resolve the current bt profile and project, and send the reconstructed historical trace through the production Braintrust sink. The source is explicit because session IDs alone do not identify their producer. Codex snapshots are streamed once, native turn IDs and compaction history replacements are retained, and large imports drain in small bounded operation batches to avoid losing later turns to bounded delivery queues without serializing a network flush for every boundary. Claude imports preserve native turn ownership when physical record order is not timestamp-monotonic and propagate Claude API-error markers into turn and LLM errors. Daemon restart recovery remains an internal WAL operation; it may idempotently resubmit rows under stable backend row IDs, but cannot create duplicate logical spans.

The foreground daemon initializes structured logging at INFO by default, or DEBUG with --verbose, and emits safe request lifecycle fields such as JSON-RPC method, request ID, event type, source, and session ID. Payloads and credentials are not logged.

bt trace setup codex and bt trace setup claude use the coding agents' own plugin managers to add the official Braintrust marketplaces and install the currently published tracing plugins. Setup also creates the shared tracing settings when needed, enables tracing, and accepts --project for routing. It performs a non-destructive merge: every other setting, including legacy authentication and backend fields needed by currently published plugins, is preserved unchanged.

The bt host resolves its normal profile, OAuth, keychain, or API-key credentials for each hook invocation and transcript import, passing the resulting token, backend URLs, organization, and project to the credential-passive daemon library. Hook errors remain fail-open so tracing cannot break a Codex or Claude Code turn.

The daemon is consumed from the exact Git commit of its migration PR rather than through a local path dependency. The integration is rebased on current bt main and preserves the newer top-level update command and command routing introduced there.

CLI regression tests verify that setup and import are advertised by bt trace --help, while the four hidden operational commands remain directly callable. They also cover the required import source and session ID, rejection of the removed replay spelling, hook options, graceful and idempotent stop, Codex and Claude plugin-manager invocations, default and explicit project selection, and preservation of existing settings. The superseded bt daemon and bt agents paths remain rejected.

Validation

  • cargo fmt --check
  • cargo test --test cli
    • all 30 CLI tests passed.
  • Daemon dependency suite: 60 tests passed under all features, including multi-turn native Codex and Claude transcript imports, non-monotonic Claude record ordering and API errors, compaction-state replacement, turn-checkpoint delivery, and restart ID stability.
  • Real installed Codex and Claude Code sessions completed against deterministic mock inference and satisfied their mock ingest trace scenarios.
  • Manual isolated lifecycle smoke delivered deterministic Codex rows to a local mock Braintrust backend with project routing and braintrust.plugin.codex span-origin metadata.
  • A real three-turn Claude transcript with non-monotonic record timestamps was imported into Braintrust; all three LLM spans were parented to their corresponding turns, native API failures were marked as errors, and re-import retained the same seven span IDs.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Latest downloadable build artifacts for this PR commit def3be2904cc:

Available artifact names
  • artifacts-build-global
  • artifacts-build-local-x86_64-apple-darwin
  • artifacts-build-local-aarch64-pc-windows-msvc
  • artifacts-build-local-x86_64-pc-windows-msvc
  • artifacts-build-local-x86_64-unknown-linux-gnu
  • artifacts-build-local-x86_64-unknown-linux-musl
  • artifacts-build-local-aarch64-apple-darwin
  • artifacts-build-local-aarch64-unknown-linux-gnu
  • artifacts-plan-dist-manifest
  • cargo-dist-cache

Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
@Qard
Stephen Belanger (Qard) force-pushed the agent/bt-daemon-integration branch from 39bbed4 to 6780c1d Compare July 30, 2026 13:55
Add bt agents setup codex and bt agents setup claude. The commands use each agent's plugin manager to install the currently published Braintrust tracing plugin without configuring the unreleased embedded daemon.

Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Create the shared tracing settings file when missing and allow --project to select the trace project. Existing settings, including legacy authentication fields, are preserved unchanged so current published plugins continue to work.

Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
@Qard
Stephen Belanger (Qard) force-pushed the agent/bt-daemon-integration branch from 3fd4543 to 9f346b6 Compare July 30, 2026 15:14
Point bt at the daemon PR commit that restores src to main, keeping the existing published plugin runtimes independent from the daemon-capable CLI release.

Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
@Qard
Stephen Belanger (Qard) force-pushed the agent/bt-daemon-integration branch from 9f346b6 to 3298cdf Compare July 30, 2026 15:24
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
Signed-off-by: Stephen Belanger <stephen.belanger@braintrustdata.com>
@ankrgyl

Copy link
Copy Markdown
Contributor
A-Goyal:~/projects/bt ankur$ bt trace import codex 019fba28-c05a-7fc2-8122-f60591056541

This worked, but i had no idea which org, project, etc. it wrote to. With other commands, if this is ambiguous, we show you a selector where you pick it.

Also, instead of just accepting a "project", we should accept the same destination format as bt sync push, which can also be to experiments, etc. Eventually we will want this to accept serialized SpanComponents so you can write to arbitrary parents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants